<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input v-model="listQuery.userName" clearable class="filter-item" style="width: 200px;" :placeholder="$t('请输入用户名称')"/>
      <el-select v-model="listQuery.payType" clearable style="width: 200px" class="filter-item" :placeholder="$t('支付方式')">
        <el-option v-for="type in payOptions" :key="type.value" :label="type.label" :value="type.value"/>
      </el-select>
      <el-input v-model="listQuery.subscribeName" clearable class="filter-item" style="width: 200px;" :placeholder="$t('请输入订阅名称')"/>

      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter" v-permission="['GET /admin/p/lumiere_subscribe_user_log_index']">{{$t('Search')}}</el-button>
    </div>

    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="list" :element-loading-text="$t('Searching')" border fit highlight-current-row>

      <el-table-column align="center" :label="$t('用户名ID')" prop="userId">
      </el-table-column>
      <el-table-column align="center" :label="$t('用户账号')" prop="userName">
      </el-table-column>
      <el-table-column align="center" :label="$t('订阅名称')" prop="subscribeName">
      </el-table-column>
      <el-table-column align="center" :label="$t('购买类型')" prop="buyType">
        <template slot-scope="scope">
          {{filterBuyType(scope.row.buyType)}}
        </template>
      </el-table-column>
      <!--订单类型(1:自提；2：外送;3:堂食；4：邮寄)-->
      <el-table-column align="center" :label="$t('金额')" prop="price">
        <template slot-scope="scope">
          {{filterPrice(scope.row)}}
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('购买时间')" prop="buyTime">
      </el-table-column>
      <el-table-column align="center" :label="$t('付款方式')" prop="payType">
        <template slot-scope="scope">
          {{filterPayType(scope.row.payType)}}
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('到期时间')"   prop="expireTime">
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

    <el-tooltip placement="top" :content="$t('Back_to_top')">
      <back-to-top :visibility-height="100" />
    </el-tooltip>
  </div>
</template>

<script>
import { goodsOps } from '@/api/goods'
import { shopOps } from '@/api/shop'
import {subscribeusers} from '@/api/subscribe'
import BackToTop from '@/components/BackToTop'
import Pagination from '@/components/Pagination'
import { querySubscribeUserList } from '../../api/subscribeUser'
import { listUserLog } from '../../api/lumiereSubscribeUserLog' // Secondary package based on el-pagination
export default {
  name: "subscribeUserLog",
  components: { BackToTop, Pagination },
  data(){

    const defaultPayOptions = [
      {
        label: this.$t('余额'),
        value: 1
      },
      {
        label: this.$t('礼物卡'),
        value: 2
      },
      {
        label: this.$t('积分'),
        value: 3
      },
      {
        label: this.$t('信用卡'),
        value: 4
      },
    ]

    return {
      defaultPayOptions,
      payOptions: Object.assign({}, defaultPayOptions),
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        payType: undefined,
        shopId: undefined,
        goodsId: undefined,
        page: 1,
        limit: 20,
        userAccount: undefined,
        sort: 'add_time',
        order: 'desc'
      },
      goodsOps: [],
      shopOps: []
    }
  },
  created() {
    this.getList()
    this.getGoodsOps();
    this.getShopOps();
  },
  methods: {
    getGoodsOps(){
      goodsOps().then(response=>{
        this.goodsOps = response.data.data
      })
    },
    getShopOps(){
      shopOps().then(response=>{
        this.shopOps = response.data.data
      })
    },
    getList() {
      this.listLoading = true
      listUserLog(this.listQuery).then(response => {
        // //debugger
        this.list = response.data.data.content
        this.total = response.data.data.totalElements
        this.listLoading = false
      }).catch(() => {
        this.list = []
        this.total = 0
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    filterBuyType(buyType){
      if(buyType == 1) {
        return this.$t('购买')
      }else if(buyType == 2){
        return this.$t('续费')
      }else{
        return this.$t('赠送')
      }
    },

    filterPayType(payType){
      if(payType == 1){
        return this.$t('余额')
      }else if(payType == 2){
        return this.$t('礼物卡')
      }else if(payType == 3){
        return this.$t('积分')
      }else if(payType == 4){
        return this.$t('信用卡')
      }
    },
    filterPrice(row){
      if(row.payType == 3){
        return row.point + 'pts'
      }else{
        return '$'+row.price
      }
    }
  }
}
</script>

<style scoped>

</style>
